%% ret = ensemble_predict(Y, model)
% classify data using models.
% code based on calculate_testing_error() in ensemble.m
% 
%C Insert "results.base_learner = base_learner;" into line 154 
% in the original ensemble.m
%
% input : 
%     Y : M*N matrix as data to predict. N is the number of features.
%  model: model (return value) you get from modified ensemble().
%
% output :
%   ret : M*1 matrix of predict value.
function ret = ensemble_predict(Y, model)
    L = model.optimal.L;
    OPTIMAL_K = model.optimal.k;
    TST.fusion_majority_vote = zeros(size(Y,1),1);
    base_learner = model.base_learner;
    for idB = 1:L
        subspace = base_learner{idB}.subspace(1:OPTIMAL_K);

        TST.proj = Y(:,subspace)*base_learner{idB}.w-base_learner{idB}.b;
        TST.fusion_majority_vote = TST.fusion_majority_vote+sign(TST.proj);
    end
    ret = sign(TST.fusion_majority_vote);
    [M,N] = size(ret);
    ret = ret + (ret == 0).*sign(rand(M,N)-0.5);
end
